package com.example.arithmeticleetcode.leetcode;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Comparator;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;

/**
 * @program: arithmetic-leetcode
 * @description: 1451. 重新排列句子中的单词
 * @author: FangZhen
 * @create: 2020-05-21 19:22
 **/
public class Demo21 {

    public static void main(String[] args) throws Exception {
        CountDownLatch countDownLatch1 = new CountDownLatch(10000);
        CountDownLatch countDownLatch2 = new CountDownLatch(10000);
        long start = System.currentTimeMillis();
        for (int i = 0, len = 10000; i < len; i++) {
            new Thread(() -> {
                try {


                    Class aClass = Class.forName("com.example.arithmeticleetcode.leetcode.A");
                    Field username = aClass.getDeclaredField("username");
                    username.setAccessible(true);
                    String name = username.getName();
                    Object o = username.get(aClass.newInstance());


                } catch (Exception e) {
                }

            }).start();
            countDownLatch1.countDown();
        }
        countDownLatch1.await();
        long end = System.currentTimeMillis();
        System.out.println("加private耗时：" + (end - start));
        long start1 = System.currentTimeMillis();
        for (int i = 0, len = 10000; i < len; i++) {
            new Thread(() -> {
                try {


                    Class aClass = Class.forName("com.example.arithmeticleetcode.leetcode.B");
                    Field username = aClass.getDeclaredField("nickname");
                    username.setAccessible(true);
                    String name = username.getName();
                    Object o = username.get(aClass.newInstance());


                } catch (Exception e) {
                }

            }).start();
            countDownLatch2.countDown();
        }

        countDownLatch2.await();
        long end1 = System.currentTimeMillis();
        System.out.println("不加private耗时：" + (end1 - start1));

    }

    public String arrangeWords(String text) {
        text = text.toLowerCase();
        String[] split = text.split(" ");
        Arrays.sort(split, Comparator.comparingInt(String::length));
        split[0] = Character.toUpperCase(split[0].charAt(0)) + split[0].substring(1);
        return String.join(" ", split);
    }
}

